package pe.edu.upc.dsd.mercadolibreres;

import java.sql.Connection;
import java.sql.PreparedStatement;

import java.sql.SQLException;



public class TransaccionDAO extends BaseDAO {
	public void  GuardarTransaccion(Transaccion vo) throws DAOExcepcion {
		
		String query = "INSERT INTO transaccion(idtransaccion, cantVentaTransac, " +
				"estadoTransac, fechTransac, idCliente, idproducto) VALUES (?,?,?,?,?,?)";
		Connection con = null;
		PreparedStatement stmt = null;
		try {
			con = ConexionBD.obtenerConexion();
			stmt = con.prepareStatement(query);
			
			stmt.setInt(1, vo.getIdtransaccion());
			stmt.setString(2, vo.getCantVentaTransac());
			stmt.setInt(3, vo.getEstdoTransac());
			stmt.setString(4, vo.getFechTransac());
			stmt.setInt (5, vo.getIdCliente());
			stmt.setInt(6, vo.getIdProducto());
			
			int i = stmt.executeUpdate();
			if (i != 1) {
				throw new SQLException("No se pudo insertar");
			}
		} catch (SQLException e) {
			System.err.println(e.getMessage());
			throw new DAOExcepcion(e.getMessage());
		} finally {
			this.cerrarStatement(stmt);
			this.cerrarConexion(con);
		}
		
		
	}
}
